package org.dtrd.modules.patient.entity.bean.miniprogram;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.dtrd.config.common.PathUtil;
import org.dtrd.config.system.Constant;
import org.dtrd.config.system.Constant.MiniProgramEventType;
import org.dtrd.modules.record.entity.po.DtrdEntRdSigninHeightWeight;
import org.dtrd.modules.record.entity.po.DtrdEntRdSigninSugarValue;

import java.util.Date;

/**
 * @author qr
 * @date 2022/3/22 15:11
 */
@ApiModel("小程序最新数据, 血糖/bmi")
@Getter
@Setter
@NoArgsConstructor
public class PatientMiniProgramLatestData {

    @ApiModelProperty("名字")
    private String name;

    @ApiModelProperty("记录事件")
    @JsonFormat(timezone = "GMT+8", pattern = "MM-dd HH:mm")
    private Date recordTime;

    @ApiModelProperty("树值")
    private String value;

    @ApiModelProperty("单位")
    private String unit;

    @ApiModelProperty("图标")
    private String icon;

    @ApiModelProperty("1-低于正常值, 2-正常, 3-高于正常值")
    private Integer status;

    @ApiModelProperty("小程序点击事件")
    private MiniprogramEventType eventType;

    public PatientMiniProgramLatestData(String name, String icon) {
        this.name = name;
        this.icon = icon;
    }

    public PatientMiniProgramLatestData parseFromPO(DtrdEntRdSigninSugarValue sugarValue) {
        name = "最新血糖";
        recordTime = sugarValue.getRecordTime();
        value = Float.toString(sugarValue.getSugarValueSugarValue());
        unit = Constant.Unit.SUGAR_VALUE_UNIT;
        icon = "https://imgs.dtx-tech.com/index_top_sugarbg.png";
        eventType = new MiniprogramEventType(MiniProgramEventType.jump_webpage.name(), PathUtil.getH5Domain()+"/patient/BloodProfile/bloodSugar.html?userid=" + sugarValue.getPatientId());
        return this;
    }

    public PatientMiniProgramLatestData paseFromPO(DtrdEntRdSigninHeightWeight heightWeight) {
        name = "最新BMI";
        recordTime = heightWeight.getRecordTime();
        value = Float.toString(heightWeight.getHeightWeightBmi());
        unit = "";
        icon = "https://imgs.dtx-tech.com/index_top_bmibg.png";
        eventType = new MiniprogramEventType(Constant.MiniProgramEventType.jump_webpage.name(), PathUtil.getH5Domain()+"/patient/BloodProfile/bmi.html?userid=" + heightWeight.getPatientId());
        return this;
    }
}
